﻿using FarPoint.Web.Spread;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ControlExplorer.samples.PrintToPDF
{
  public partial class Overview : SpreadDemoPage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (IsPostBack) return;
      FpSpread1.Open(Server.MapPath("printtopdf.xml"));
      this.FpSpread1.Sheets[1].PrintInfo.Footer = "http://www.gcpowertools.com.cn//r/cl\"4\"This is page /p of /pc/n/c/g\"0\"";
      this.FpSpread1.Sheets[1].PrintInfo.Header = "/fn\"Book Antiqua\" /fz\"14\" Print to PDF Test Page for FarPoint Inc./n";
      this.FpSpread1.Sheets[1].PrintInfo.Colors = new Color[] { Color.Green, Color.Yellow, Color.Gold, Color.Indigo, Color.Brown };
      this.FpSpread1.Sheets[1].PrintInfo.Images = new System.Drawing.Image[] { System.Drawing.Image.FromFile(MapPath("../images/v4_title.gif")) };
      this.FpSpread1.UseClipboard = false;
    }

    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {
      this.FpSpread1.Sheets[0].PrintInfo.Opacity = 150;
      this.FpSpread1.Sheets[1].PrintInfo.Opacity = 150;
      switch (e.Item.Value)
      {
        case "0":
          this.FpSpread1.Sheets[0].PrintInfo.Opacity = 255;
          this.FpSpread1.Sheets[1].PrintInfo.Opacity = 255;
          this.FpSpread1.SavePdfToResponse("PdfTest.pdf");
          break;
        case "1":
          this.FpSpread1.PrintBackground += new FarPoint.Web.Spread.PrintBackgroundEventHandler(FpSpread1_PrintBackground);
          this.FpSpread1.SavePdfToResponse("PdfTest.pdf");
          break;
        case "2":
          this.FpSpread1.PrintBackground += new FarPoint.Web.Spread.PrintBackgroundEventHandler(FpSpread1_PrintBackground);
          this.FpSpread1.SavePdfToResponse(0, "PdfTest.pdf", false);
          break;
        case "3":
          this.FpSpread1.Sheets[0].PrintInfo.Opacity = 255;
          this.FpSpread1.Sheets[1].PrintInfo.Opacity = 255;
          this.FpSpread1.SavePdfToResponse(1, "PdfTest.pdf", false);
          break;
      }
    }

    void FpSpread1_PrintBackground(object sender, FarPoint.Web.Spread.PrintBackgroundEventArgs e)
    {
      Graphics g = e.Graphics;
      if (g != null)
      {
        using (System.Drawing.Image b = System.Drawing.Image.FromFile(MapPath("../images/v4_title.gif")))
        {
          g.DrawImage(b, e.SheetRectangle.X + (e.SheetRectangle.Width - b.Width) / 2, e.SheetRectangle.Y + (e.SheetRectangle.Height - b.Height) / 2 + 20);
        }
      }
    }
  }
}